import axios from "../axios";
import apiList from "./api-list";
import type { DictVO, QueryDictVO } from "./types";

class DictController {
    getDictType() {
        return axios.get<string[]>(apiList.getDictType, {});
    }
    create(data: DictVO) {
        return axios.post(apiList.create, data);
    }
    update(data: DictVO) {
        return axios.post(apiList.update, data);
    }
    delete(data: DictVO) {
        return axios.post(apiList.delete, data);
    }
    async list(dictType: string, filterDemo?: boolean) {
        const response = await axios.get<DictVO[]>(apiList.list, { dictType });
        if (response.success && filterDemo === true) {
            response.data = response.data.filter(x => x.code !== "DEMO");
        }
        return response;
    }
    page(query: QueryDictVO) {
        return axios.post<DictVO[]>(apiList.page, query);
    }
}

export default DictController;